import React from 'react';
import ReactDOM from 'react-dom';

import { HashRouter as Router, Route, Switch} from 'react-router-dom'
import { Provider } from 'mobx-react';
import { asyncComponent } from 'react-async-component';
import { Tools,Bubble } from 'weaver-mobile';
import { FloatingTouch } from 'weaver-mobile-page'; 
import allStore from './stores';
import './util/siriwave.js';

import './style';
// const getLocaleLabel = Tools.getLocaleLabel.bind(this, 'workplan_mobile');
const getLabel = Tools.getLabel;
const coms = {
  Home: asyncComponent({
    resolve: () => import("./components/main")
  }),
  ViewWorkplan: asyncComponent({
    resolve: () => import("./components/detail/singleDetail")
  }),
  Workplan: asyncComponent({
    resolve: () => import("./components/calendar")
  }),
  EditWorkplan: asyncComponent({
    resolve: () => import("./components/add")
  }),
  SearchWorkplan: asyncComponent({
    resolve: () => import("./components/search")
  }),
  Create: asyncComponent({
    resolve: () => import("./components/create")
  }),
  Calendar: asyncComponent({
    resolve: () => import("./components/calendar")
  }),
  Schedule: asyncComponent({
    resolve: () => import("./components/calendar/schedule")
  }),
  HrmWorkplan: asyncComponent({
    resolve: () => import("./components/calendar/hrmWorkplan")
  }),
  Remind: asyncComponent({
    resolve: () => import("./components/create/remind")
  }),
  RepeatType: asyncComponent({
    resolve: () => import("./components/create/repeatType")
  }),
  OneWeekWorkplan: asyncComponent({
    resolve: () => import("./components/oneWeekWorkplan/index")
  }),
  WorkplanViewList: asyncComponent({
    resolve: () => import("./components/workplanViewList/index")
  }),
}

class Root extends React.Component {

  getLocaleLabel = Tools.getLocaleLabel;

  // constructor(props) {
  //   super(props);
  //   this.state = {
  //     loadLang: false
  //   }
  //   this.getLocaleLabel.bind(this);
  
  // }
  // componentDidMount() {
  //   Tools.ssoInit().then(() => {
  //     this.getLocaleLabel('workplan_mobile', () => {
  //       this.setState({loadLang: true});
  //     });
  //   }).catch((res) => {
  //     Bubble.error(getLabel(386481, '登录失败') + "," + JSON.stringify(res), 0);
  //   });
  // }

  onHomePageClick() {
    window.location.href = '/#/';
  }

  render() {
    return (
      <Provider {...allStore}>
      <Router>
        <FloatingTouch onClick={() => this.onHomePageClick()}>
          <Route name="home" path="/" component={() => {
              // if(!this.state.loadLang){
              //   return <div></div>
              // }else{
                return (<coms.Home>
                <Switch>
                  {/* <Route name="repeattype" path="/repeattype" breadcrumbName="自定义周期日程提醒" component={coms.RepeatType} /> */}
                  <Route name="remind" path="/remind" breadcrumbName="提醒方式" component={coms.Remind} />
                  <Route name="calendar" path="/calendar" breadcrumbName="日程" component={coms.Workplan} />
                  <Route name="detail" path="/detail" breadcrumbName="查看日程" component={coms.ViewWorkplan} />
                  <Route name="add" path="/add" breadcrumbName="" component={coms.EditWorkplan} />
                  <Route name="edit" path="/edit" breadcrumbName="" component={coms.EditWorkplan} />
                  <Route name="search" path="/search" breadcrumbName="" component={coms.SearchWorkplan} />
                  <Route name="create" path="/create" breadcrumbName="新建日程" component={coms.Create} />
                  <Route name="schedule" path="/schedule" breadcrumbName="日程日历" component={coms.Schedule} />
                  <Route name="hrmWorkplan" path="/hrmWorkplan" breadcrumbName="下属或关注日程" component={coms.HrmWorkplan} />
                  <Route name="oneWeekWorkplan" path="/oneWeekWorkplan" breadcrumbName="一周日程安排" component={coms.OneWeekWorkplan} />
                  <Route name="workplanViewList" path="/calendar/myCalendar/report/workplanViewList" breadcrumbName="日程一览表" component={coms.WorkplanViewList} />
                </Switch>
              </coms.Home>)
              // }
            }} />
        </FloatingTouch>
      </Router>
      </Provider>
    )
  }
}
Tools.getLocaleLabel('workplan_mobile',() => {
  ReactDOM.render(<Root />, document.getElementById('root'))
})